using UnityEngine;

public class BoomController : MonoBehaviour
{
	private float distance;

	public GameObject EffOfBoom;

	private GameObject _target;

	private GameObject[] player;

	private GameObject[] enemy;

	private int damageboomInBoss;

	private int damageboomInPlayer;

	private void Start()
	{
		Invoke("BoomExploder", UnityEngine.Random.Range(4.2f, 5.1f));
		if (!GameManager.isHard)
		{
			damageboomInPlayer = 5000;
			damageboomInBoss = 8000;
		}
		else
		{
			damageboomInPlayer = 15000;
			damageboomInBoss = 15000;
		}
	}

	private void BoomExploder()
	{
		AudioController.Instance.SoundBoomBoss3();
		GameObject obj = UnityEngine.Object.Instantiate(EffOfBoom, base.transform.position, Quaternion.identity);
		FindTarget();
		FindEnemy();
		UnityEngine.Object.Destroy(base.gameObject);
		GameManager.AllBoom.Remove(base.gameObject);
		UnityEngine.Object.Destroy(obj, 0.8f);
	}

	private void OnCollisionEnter2D(Collision2D other)
	{
		if (other.gameObject.tag == "Boss")
		{
			AudioController.Instance.SoundBoomBoss3();
			other.gameObject.GetComponent<EnemyController>().Hit_Player(8000, a: false, 0);
			GameObject obj = UnityEngine.Object.Instantiate(EffOfBoom, base.transform.position, Quaternion.identity);
			UnityEngine.Object.Destroy(obj, 0.8f);
			UnityEngine.Object.Destroy(base.gameObject, 0.1f);
			GameManager.AllBoom.Remove(base.gameObject);
		}
	}

	private void FindTarget()
	{
		player = GameObject.FindGameObjectsWithTag("Player");
		for (int i = 0; i < player.Length; i++)
		{
			Vector3 position = base.transform.position;
			float x = position.x;
			Vector3 position2 = player[i].transform.position;
			distance = Mathf.Abs(x - position2.x);
			if (distance < 1.1f && !GameManager.isWin)
			{
				player[i].GetComponent<PlayerController>().Hit_Enemy(damageboomInPlayer);
			}
		}
	}

	private void FindEnemy()
	{
		enemy = GameObject.FindGameObjectsWithTag("Enemy");
		for (int i = 0; i < enemy.Length; i++)
		{
			Vector3 position = base.transform.position;
			float x = position.x;
			Vector3 position2 = enemy[i].transform.position;
			distance = Mathf.Abs(x - position2.x);
			if (distance < 1.1f && !GameManager.isWin)
			{
				enemy[i].GetComponent<EnemyController>().Hit_Player(damageboomInBoss, a: true, 2);
			}
		}
	}
}
